/**
 * 创建所有的job
 */
var config = require('../config');
var schedule = require('node-schedule');
var AV = require('leanengine');
var log4js = require('log4js');
var orderM = require('./order.js');
log4js.configure(config.log4js);
var logger = log4js.getLogger('normal');
require('date-utils');
logger.setLevel('DEBUG');
module.exports = {
    cancelOrder : function(orderid){
        var theOrderM = orderM;
        var job = new schedule.Job(function() {
            logger.info(orderid);
            theOrderM.setOrderCancel(orderid).then(function(order){
                //根据订单的状态进行更新
                logger.debug('cancelOrder Success: ' + JSON.stringify(order));
            }).catch(function(err){
                logger.error('cancelOrder ERROR: ' + JSON.stringify(err));
            });
        });
        //2小时后执行
        job.schedule(new Date(Date.now() + 2 * 60 * 60 * 1000 ));
        return job;
    },

};


/*
* 调用实例:
* job.cancelOrder(orderid)
* */